#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
class Solution{
public:
	// 2,7,11,15 二分法
	vector<int> twoSum(vector<int>& nums, int target){
		int len = nums.size();
		for(int i =0;i<1;i++){
			int t1 = target-nums[i];
			int left = i+1;
			int right = len-1;
			int mid = (left+right)/2;
			while(left <= right){
				if(nums[mid] == t1){
					return {i,mid};
				}
				if(nums[mid]<t1){
					left=mid+1;
				}else{
					right=mid-1;
				}
				mid=(left+right)/2;
			}
		}
		return {-1,-1};
	}
	
	// 双指针法
	vector<int> twoSum1(vector<int>& nums, int target){
		int i = 0;
		int j = nums.size()-1;
		while(i<j){
			if(nums[i]+nums[j]==target){
				return {i,j};
			}
			if(nums[i]+nums[j]<target){
				i++;
			}
			if(nums[i]+nums[j]>target){
				j--;
			}
		}
		return {-1,-1};
	}
};

int main(){
	vector<int> nums = {2,3,4};
	int target = 6;
	Solution so;
	vector<int> a = so.twoSum(nums, target);
	for(auto i : a){
		cout << i << " ";
	}
	cout << endl;
	return 0;
}